package com.um.info.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.cs.framework.common.bo.Message;
import com.cs.framework.ui.bo.UIData;
import com.cs.framework.ui.web.UI;
import com.cs.framework.web.annotation.Action;
import com.cs.framework.web.annotation.Mapping;
import com.cs.framework.web.handler.Web;
import com.um.info.dto.base.UmUserDto;
import com.um.info.service.UmUserService;

/**
 * UM用户
 *
 * @author hedongzhou
 *
 */
@Action("umUser")
public class UmUserAction {

	private Log logger = LogFactory.getLog(getClass());

	@Resource
	private UmUserService umUserService;

	/**
	 * 进入用户信息管理页面
	 */
	@Mapping
	public void mainPage() {
		UI.returnPage("um_user");
	}

	/**
	 * 查询UM用户
	 */
	@Mapping
	public Object query() {
		UmUserDto umUserDto = Web.bind(UmUserDto.class);

		List<UmUserDto> list = umUserService.query(umUserDto);
		int count = umUserService.count(umUserDto);

		return new UIData(list, count);
	}

	/**
	 * 新增UM用户
	 */
	@Mapping
	public Object save() {
		UmUserDto umUserDto = Web.bind(UmUserDto.class);

		try {
			umUserService.save(umUserDto);

			return new Message("Y", "新增成功");
		} catch (Exception e) {
			logger.error(e.getMessage(), e);

			return new Message("N", e.getMessage());
		}
	}

	/**
	 * 修改UM用户
	 */
	@Mapping
	public Object update() {
		UmUserDto umUserDto = Web.bind(UmUserDto.class);

		try {
			umUserService.update(umUserDto);

			return new Message("Y", "修改成功");
		} catch (Exception e) {
			logger.error(e.getMessage(), e);

			return new Message("N", e.getMessage());
		}
	}

}
